package com.example.nio.utils;

import cn.hutool.json.JSONUtil;
import com.example.nio.commons.Agent;
import com.example.nio.commons.ChatMessage;
import com.example.nio.commons.Message;
import com.example.nio.commons.User;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

import java.util.List;

public class BridgeUtil {
    //服务器发送信息到客户端
    public static void toClient(ChatMessage chatMessage, Agent agent){
        Channel channel=agent.getChannel();
        channel.writeAndFlush(new TextWebSocketFrame(JSONUtil.toJsonStr(chatMessage)));
    }

    //服务器发送集合到客户端
    public static void toClientByList(List<User> userList, Agent agent){
        Channel channel=agent.getChannel();
        channel.writeAndFlush(new TextWebSocketFrame(userList.toString()));
    }

}
